﻿@model LogListModel
@{
    ResLink.AddCss("~/res/css/log/list.css");
}

<h1>로그기록</h1>
<hr />

<div class="pull-right">
    <a class="btn btn-small" onclick="전체선택()">전체선택</a>
    <a class="btn btn-small" onclick="삭제()">삭제</a>
</div>

<div class="form-inline">
    정렬:
    @Html.DropDownListFor(m => m.pagination.order, BL로그기록.정렬순서목록, new { onchange = "정렬순서변경(this.value)" })

    @Html.DropDownListFor(m => m.pagination.srchType, BL로그기록.검색유형목록)
    @Html.TextBoxFor(m => m.pagination.srchText)
    <a class="btn btn-small" onclick="검색()">검색</a>
</div>

<form id="로그목록">
    <table class="table table-condensed table-bordered">
        <thead>
            <tr>
                <th></th>
                <th>사용자</th>
                <th>IP</th>
                <th>URL</th>
                <th>구분</th>
                <th>일시</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var 항목 in Model.로그목록) {            
                <tr onclick="location.href = '@Url.Action("Log", "Log", new { id = 항목.ID })'">
                    <td onclick="event.stopPropagation()"><input type="checkbox" name="ID" value="@항목.ID" /></td>
                    <td>@항목.사용자</td>
                    <td>@항목.IP</td>
                    <td>@항목.URL</td>
                    <td>@항목.구분</td>
                    <td>@항목.일시.ToYMDHMS()</td>
                </tr>
            }
        </tbody>
    </table>
</form>

<div class="controls pull-right form-inline">
    화면크기: 
    @Html.DropDownListFor(m => m.pagination.size, new SelectList(Consts.페이지크기목록), new { onchange = "페이지크기변경(this.value)" })
</div>

@Html.Partial("_Pagination", Model.pagination)

<script type="text/javascript">
    function 페이지크기변경(size) {
        var url = '@Html.Raw(Url.LogListResize(9991))';
        location.href = url.replace("9991", size);
    }

    function 정렬순서변경(order) {
        var url = '@Html.Raw(Url.LogListSort(9991))';
        location.href = url.replace("9991", order);
    }

    function 검색() {
        var url = '@Html.Raw(Url.LogListSearch(9991, "9992"))';
        var 검색유형 = $('select[name$=srchType]').val();
        var 검색어 = encodeURIComponent($('input[name$=srchText]').val().trim());
        location.href = url.replace("9991", 검색유형).replace("9992", 검색어);
    }

    function 전체선택() {
        if ($("table input[type=checkbox]:nth-child(1)").is(':checked'))
            $("table input[type=checkbox]").attr("checked", false);
        else
            $("table input[type=checkbox]").attr("checked", true);
    }

    function 삭제() {
        if ($("form#로그목록 input[type=checkbox]:checked").length <= 0) {
            alert("선택된 항목이 없습니다");
            return;
        }
        AjaxPostForm($('form#로그목록'), '@Url.MyAction("DeleteList", "Log")');
    }
</script>